package ch.ethz.inf.shop.model.simpleDatabase;

import java.util.HashMap;
import java.util.List;

/**
 * The schema contains meta data about a tuple. So far we only store the name of
 * each column. Other meta data, such cardinalities, indexes, etc. could be
 * specified here.
 */
public class TupleSchema {

	private final List<String> columnNames;

	private final HashMap<String, Integer> columnNamesMap;

	/**
	 * Constructs a new tuple schema.
	 * 
	 * @param columnNames
	 *            column names
	 */
	public TupleSchema(final List<String> columnNames) {
		this.columnNames = columnNames;

		this.columnNamesMap = new HashMap<String, Integer>();
		int i = 0;
		for (String string : columnNames) {
			this.columnNamesMap.put(string.toUpperCase(), i++);
		}
	}

	/**
	 * Given the name of a column, returns the index in the respective tuple.
	 * 
	 * @param column
	 *            column name
	 * @return index of column in tuple
	 */
	public int getIndex(final String column) {
		final Integer index = this.columnNamesMap.get(column.toUpperCase());
		return index == null ? -1 : index;
	}

	public List<String> getColumnNames() {
		return columnNames;
	}
}
